package com.itheima.canal.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    private static final String AD_UPDATE_EXCHANGE = "ad_update_exchange";
    private static final String GOODS_UPDATE_EXCHANGE = "goods_update_exchange";
    private static final String AD_UPDATE_QUEUE = "ad_update_queue";
    private static final String GOODS_UPDATE_QUEUE = "goods_update_queue";

    @Bean("AD_UPDATE_EXCHANGE")
    public Exchange AD_UPDATE_EXCHANGE() {
        return ExchangeBuilder.fanoutExchange(AD_UPDATE_EXCHANGE).durable(true).build();
    }
    @Bean("GOODS_UPDATE_EXCHANGE")
    public Exchange GOODS_UPDATE_EXCHANGE() {
        return ExchangeBuilder.fanoutExchange(GOODS_UPDATE_EXCHANGE).durable(true).build();
    }

    @Bean("AD_UPDATE_QUEUE")
    public Queue AD_UPDATE_QUEUE() {
        return QueueBuilder.durable(AD_UPDATE_QUEUE).build();
    }

    @Bean("GOODS_UPDATE_QUEUE")
    public Queue GOODS_UPDATE_QUEUE() {
        return QueueBuilder.durable(GOODS_UPDATE_QUEUE).build();
    }

    @Bean
    public Binding binding(@Qualifier("AD_UPDATE_QUEUE") Queue queue1,@Qualifier("AD_UPDATE_EXCHANGE") Exchange exchange) {
        return BindingBuilder.bind(queue1).to(exchange).with("").noargs();
    }
    @Bean
    public Binding binding2(@Qualifier("GOODS_UPDATE_QUEUE") Queue queue,@Qualifier("GOODS_UPDATE_EXCHANGE") Exchange exchange1) {
        return BindingBuilder.bind(queue).to(exchange1).with("").noargs();
    }

}
